package br.ufla.pgcc.oomeasures.measures;

import org.eclipse.jdt.core.dom.CompilationUnit;

import br.ufla.pgcc.oomeasures.astvisitors.CommentRatioVisitor;

/**
 * O nome da metrica mudou de Number of Commented Lines para Number of Comments (NOC).
 * Para manter a integridade o nome da classe e referencias nao foram modificados.
 */

public class NumberOfComments extends Measure {

	private double value;

	public NumberOfComments() {
		super();
		value = 0d;
		addApplicableGranularity(Granularity.CLASS);
	}

	@Override
	public String getName() {
		return "Number of comments";
	}

	@Override
	public String getAcronym() {
		return "NOC";
	}

	@Override
	public String getDescription() {
		return "Return the number of comments";
	}

	@Override
	public double getMinValue() {
		return 0;
	}

	@Override
	public double getMaxValue() {
		return 0;
	}

	@Override
	public double getRefValue() {
		return 0;
	}

	@Override
	public <T> void measure(T unit) {

		// Now create the AST for the ICompilationUnits
		CompilationUnit parse = parse(unit);
		CommentRatioVisitor visitor = new CommentRatioVisitor();
		parse.accept(visitor);
		value = visitor.getNumberOfCommentedLines(); 
	}

	@Override
	public double getCalculatedValue() {
		return value;
	}

	@Override
	public void setCalculatedValue(double value) {
		this.value = value; 
	}
}
	

